//
//  myPresenter.m
//  MVPDemo
//
//  Created by mobao on 16/6/20.
//  Copyright © 2016年 mobao. All rights reserved.
//

#import "MyPresenter.h"

@interface MyPresenter(){
    ViewController *viewController;
}

@end


@implementation MyPresenter

-(instancetype)initWithViewController:(UIViewController *)viewC{
    self = [super initWithViewController:viewC];
    if (self) {
        viewController= (ViewController*)self.vc;
    }
    return self;
}

-(void)loginWithAccount:(NSString*)accuout password:(NSString*)password{
    NSLog(@"MyPresenter logining...");
    if ([self.myPresenterDelegate respondsToSelector:@selector(logining:)]) {
        [self.myPresenterDelegate logining:@"MyPresenter logining..."];
    }
    //此处模拟网络请求数据,2秒延迟
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 2秒后异步执行这里的代码...
        // 登录成功或失败，返回数据给界面（实际应用中，此处写：访问登录接口）
        if ([accuout isEqualToString:@"vampire"]&&[password isEqualToString:@"123"]) {
            //此处调用代理方法，将值传给界面
            if ([self.myPresenterDelegate respondsToSelector:@selector(loginSuccess:)]) {
                [self.myPresenterDelegate loginSuccess:@"login success"];
            }
        }else{
            if ([self.myPresenterDelegate respondsToSelector:@selector(loginFailure:)]) {
                [self.myPresenterDelegate loginFailure:@"login failure"];
            }
        }
        
    });
    
}
@end
